﻿namespace FKMC.Test.Database
{
    using System;
    using System.Configuration;
    using System.IO;
    using Core.Configuration;
    using Domain;
    using FluentNHibernate.Cfg;
    using FluentNHibernate.Cfg.Db;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using NHibernate;
    using NHibernate.Cfg;
    using NHibernate.Tool.hbm2ddl;
    using NHibernate.Type;
    using FluentNHibernate.Data;

    [TestClass]
    public class DatabaseCreateTest
    {
        public static string DbFile = "firstProject.db";
        [TestMethod]
        public void GenerateDatabase()
        {
            var nhibernateConfiguration = new NhibernateConfigurations();
            var session = nhibernateConfiguration.CreateSessionFactory(true).OpenSession();
          var tr=  session.BeginTransaction();
          
          CreateUser(session, "cakir@mesutcakir.com.tr", "mesutcakir", "123456", new DateTime(1991, 11, 7));
          CreateUser(session, "faruk@xxx.com.tr", "faruk", "123456", new DateTime(1993, 11, 7));
          //:)
          var product = new Product();//public olmazsa diğer taraflardan ulaşışmaz
           

            

           //örnek user ekliyorum
            //for (int i = 0; i < 100; i++)
            //{
            //     CreateUser(session, "mail@mail.com" + i, "username" + i, "password", DateTime.Now);
            //}

          for (int i = 0; i < 100; i++)
          {
              CreateProduct(session, "PC" + i, "37" + i);
          }

                           tr.Commit();


        }

        private User CreateUser(ISession session,string mail,string username,string password,DateTime? birtDate)
        {
            var user = new User
            {
                Mail = mail,
                BirtDate = birtDate,
                Password =password,
                UserName =username
            };
            session.Save(user);
            return user;
        }

        private Product CreateProduct(ISession session, string name, string price)
        {
            var product = new Product
            {
                Name = name,
                Price = price
               
            };
            session.Save(product);
            return product;
        }
        
        

    }

}